#include <bits/stdc++.h>

# define INF 0x7fffffff;  // 无穷大
typedef long long ll;

using namespace std;

class Solution {
public:
    int countDays(int days, vector<vector<int>>& meetings) {
        sort(meetings.begin(), meetings.end(), [](vector<int>& a, vector<int>& b) {
            if (a[0] != b[0]) return a[0] < b[0];
            return b[1] < a[1];
        });
        int ans = 0, e = 0;
        for (auto meeting : meetings) {
            if (meeting[0] > e) {
                ans += meeting[0] - e - 1;
            }
            e = max(e, meeting[1]);
        }
        ans += days - e;
        return ans;
    }
};

int main(int argc, const char** argv) {
    Solution s;
    vector<vector<int>> data = {{5,7},{1,3},{9,10}};
    auto res = s.countDays(10, data);
    std::cout << res << std::endl;
    return 0;
}
